/*
 * Copyright (C) 2014 Snark
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package dominions.pkg4.mod.editor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Scalie
 */
public class ArmorDatabase implements java.io.Serializable {
    
    public static List<Armor> armorDatabase = new ArrayList<Armor>();
    public static List<Armor> legDatabase = new ArrayList<Armor>();
    public static List<Armor> helmetDatabase = new ArrayList<Armor>();
    public static List<Armor> cloakDatabase = new ArrayList<Armor>();
    
    public void Load(String loadpath, String type)
    {
        FileInputStream fileIn = null;
        try {
            Armor temp = new Armor();
            System.out.println(loadpath);
            fileIn = new FileInputStream(loadpath);
            ObjectInputStream in = new ObjectInputStream(fileIn);
            temp = (Armor) in.readObject();
            in.close();
            fileIn.close();
            if(type == "Body")
            {
                if(!armorDatabase.contains(temp))
                {
                 System.out.println("Adding: " + temp);
                armorDatabase.add(temp);
                }
            }
            else if(type == "Leg")
            {
                legDatabase.add(temp);
            }
            else if(type == "Hemet")
            {
                helmetDatabase.add(temp);
            }
            else if(type == "Cloak")
            {
                cloakDatabase.add(temp);
            }
            
        } catch (FileNotFoundException ex) {
            Logger.getLogger(ArmorDatabase.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(ArmorDatabase.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(ArmorDatabase.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                fileIn.close();
            } catch (IOException ex) {
                Logger.getLogger(ArmorDatabase.class.getName()).log(Level.SEVERE, null, ex);
            }
        } 
    }
    
    public void Remove(int index)
    {
        armorDatabase.remove(index);
    }
    
}
